package com.ruoyi.web.controller.ring.app;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.Builder;
import com.ruoyi.ring.domain.RingAppNotice;
import com.ruoyi.ring.service.IRingAppNoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * app消息 app
 * 
 */
@Slf4j
@RestController
@RequestMapping("/ring/app_notice")
public class AppNoticeController extends BaseController
{
    @Resource
    private IRingAppNoticeService ringAppNoticeService;

    /**
     * 查询app消息列表  app
     */
    @GetMapping("/query-app-notice-list")
    public TableDataInfo queryAppNoticeList(RingAppNotice ringAppNotice)
    {
        long userId = SecurityUtils.getUserId();
        log.info("查询app消息列表queryAppNoticeList: userId={}, param={}", userId, JSON.toJSONString(ringAppNotice));
        startPage();
        ringAppNotice.setUserId(SecurityUtils.getUserId());
        ringAppNotice.setNoticeType("1");
        List<RingAppNotice> list = ringAppNoticeService.selectRingAppNoticeList(ringAppNotice);
        return getDataTable(list);
    }


    /**
     * 获取app消息详细信息  app
     */
    @GetMapping(value = "/query-app-notice/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Integer noticeId)
    {
        ringAppNoticeService.updateRingAppNotice(Builder.of(RingAppNotice::new).
                with(RingAppNotice::setNoticeId,noticeId).
                with(RingAppNotice::setStatus,"1").build());
        return AjaxResult.success(ringAppNoticeService.selectRingAppNoticeByNoticeId(noticeId));
    }

    /**
     * 查看app消息 app
     */
    @GetMapping(value = "/query-app-notice-info")
    public AjaxResult queryAppNotice()
    {
        return AjaxResult.success(ringAppNoticeService.selectOneRingAppNotice(Builder.of(RingAppNotice::new).
                with(RingAppNotice::setUserId,SecurityUtils.getUserId()).
                with(RingAppNotice::setRecordDate, DateUtils.dateTime(DateUtils.YYYY_MM_DD, DateUtils.getDate())).build()));
    }

}
